package com.ruoyi.buss.home.service.impl;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.buss.customer.domain.DataCustomerBankRelation;
import com.ruoyi.buss.customer.domain.DataCustomerInfo;
import com.ruoyi.buss.customer.mapper.DataCustomerBankRelationMapper;
import com.ruoyi.buss.customer.mapper.DataCustomerInfoMapper;
import com.ruoyi.buss.grid.cj.domain.DataWgWgcjVillage;
import com.ruoyi.buss.grid.cj.mapper.DataWgWgcjVillageMapper;
import com.ruoyi.buss.grid.sh.domain.DataWgShsurvey;
import com.ruoyi.buss.grid.sh.mapper.DataGtgshMapper;
import com.ruoyi.buss.grid.sq.domain.DataWgWgsqSq;
import com.ruoyi.buss.grid.sq.mapper.DataWgWgsqSqMapper;
import com.ruoyi.buss.home.mapper.HomeMapper;
import com.ruoyi.buss.home.service.IHomeService;
import com.ruoyi.buss.qmcy.domain.QmcyCustCksd;
import com.ruoyi.buss.qmcy.domain.QmcyCustDkmx;
import com.ruoyi.buss.qmcy.domain.QmcyCustLicaiSaleinfo;
import com.ruoyi.buss.qmcy.domain.QmcyCustPersonalInfo;
import com.ruoyi.buss.qmcy.domain.QmcyCustZhjy;
import com.ruoyi.buss.qmcy.mapper.QmcyCustCksdMapper;
import com.ruoyi.buss.qmcy.mapper.QmcyCustDkmxMapper;
import com.ruoyi.buss.qmcy.mapper.QmcyCustLicaiSaleinfoMapper;
import com.ruoyi.buss.qmcy.mapper.QmcyCustPersonalInfoMapper;
import com.ruoyi.buss.qmcy.mapper.QmcyCustZhjyMapper;
import com.ruoyi.buss.report.domain.AdvanceHk;
import com.ruoyi.buss.utils.DateUtilss;
import com.ruoyi.buss.utils.Params;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.api.RemoteConfigService;
import com.ruoyi.system.api.model.LoginUser;

@Service
public class HomeServiceImpl implements IHomeService {

    @Autowired
    private HomeMapper homeMapper;

    @Autowired
    private DataCustomerInfoMapper dataCustomerInfoMapper;

    @Autowired
    private QmcyCustZhjyMapper qmcyCustZhjyMapper;

    @Autowired
    private QmcyCustDkmxMapper qmcyCustDkmxMapper;

    @Autowired
    private QmcyCustLicaiSaleinfoMapper qmcyCustLicaiSaleinfoMapper;

    @Autowired
    private QmcyCustCksdMapper qmcyCustCksdMapper;

    @Autowired
    private QmcyCustPersonalInfoMapper qmcyCustPersonalInfoMapper;

    @Autowired
    private DataCustomerBankRelationMapper dataCustomerBankRelationMapper;

    @Autowired
    private DataGtgshMapper dataGtgshMapper;

    @Autowired
    private DataWgWgcjVillageMapper dataWgWgcjVillageMapper;

    @Autowired
    private DataWgWgsqSqMapper dataWgWgsqSqMapper;

    @Autowired
    private RemoteConfigService remoteConfigService;


    /**
     * 查询大额资金变动信息
     * @param qmcyCustZhjy
     * @param userInfo
     * @return
     */
    @Override
    public List<QmcyCustZhjy> largeFundReminderMore(QmcyCustZhjy qmcyCustZhjy, LoginUser userInfo) {
        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        List<QmcyCustZhjy> doList = new ArrayList<>();

        if(userInfo.getRoles().contains("zhhz")){
            qmcyCustZhjy.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
            qmcyCustZhjy.setOrgId(orgId);
            qmcyCustZhjy.setUserId(userId);
        } else {
            qmcyCustZhjy.setOrgId("");
            qmcyCustZhjy.setUserId("");
        }

        doList = qmcyCustZhjyMapper.dezjMore(qmcyCustZhjy); // 总行查询

        return doList;
    }

    /**
     * 查询大额资金公共池变动信息公共池
     * @param qmcyCustZhjy
     * @param userInfo
     * @return
     */
    @Override
    public List<QmcyCustZhjy> largeFundReminderGgc(QmcyCustZhjy qmcyCustZhjy, LoginUser userInfo) {
        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        List<QmcyCustZhjy> doList = new ArrayList<>();
        if (userInfo.getRoles().contains("admin") || userInfo.getRoles().contains("office")) {
        	qmcyCustZhjy.setUserId(userId);
        } else if(userInfo.getRoles().contains("zhhz")){
            qmcyCustZhjy.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
            qmcyCustZhjy.setOrgId(orgId);
        } else {
        	return doList;
        }

        doList = qmcyCustZhjyMapper.largeFundReminderGgc(qmcyCustZhjy); // 总行查询

        return doList;
    }

    /**
     * 贷款产品到期提醒
     * @param qmcyCustDkmx
     * @param userInfo
     * @return
     */
    @Override
    public List<QmcyCustDkmx> productExpireDKMore(QmcyCustDkmx qmcyCustDkmx, LoginUser userInfo) {
        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        List<QmcyCustDkmx> doList = new ArrayList<>();

        if(userInfo.getRoles().contains("zhhz")){
            qmcyCustDkmx.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
            qmcyCustDkmx.setOrgId(orgId);
            qmcyCustDkmx.setUserId(userId);
        } else {
            qmcyCustDkmx.setOrgId("");
            qmcyCustDkmx.setUserId("");
        }

        doList = qmcyCustDkmxMapper.productExpireDk(qmcyCustDkmx);

        return doList;
    }

    /**
     * 贷款产品到期提醒公共池
     * @param qmcyCustDkmx
     * @param userInfo
     * @return
     */
    @Override
    public List<QmcyCustDkmx> productExpireDKGgc(QmcyCustDkmx qmcyCustDkmx, LoginUser userInfo) {
        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        List<QmcyCustDkmx> doList = new ArrayList<>();

        if (userInfo.getRoles().contains("admin") || userInfo.getRoles().contains("office")) {
        	qmcyCustDkmx.setUserId(userId);
        } else if(userInfo.getRoles().contains("zhhz")){
        	qmcyCustDkmx.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
        	qmcyCustDkmx.setOrgId(orgId);
        } else {
        	return doList;
        }

        doList = qmcyCustDkmxMapper.productExpireDKGgc(qmcyCustDkmx);

        return doList;
    }

    /**
     * 理财产品到期提醒
     * @param qmcyCustLicaiSaleinfo
     * @param userInfo
     * @return
     */
    @Override
    public List<QmcyCustLicaiSaleinfo> productExpireLcMore(QmcyCustLicaiSaleinfo qmcyCustLicaiSaleinfo, LoginUser userInfo) {
        List<QmcyCustLicaiSaleinfo> doList = new ArrayList<QmcyCustLicaiSaleinfo>();

        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        if(userInfo.getRoles().contains("zhhz")){
            qmcyCustLicaiSaleinfo.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
            qmcyCustLicaiSaleinfo.setOrgId(orgId);
            qmcyCustLicaiSaleinfo.setUserId(userId);
        } else {
            qmcyCustLicaiSaleinfo.setOrgId("");
            qmcyCustLicaiSaleinfo.setUserId("");
        }

        doList = qmcyCustLicaiSaleinfoMapper.productExpireLc(qmcyCustLicaiSaleinfo);

        return doList;
    }

    /**
     * 理财产品到期提醒
     * @param qmcyCustLicaiSaleinfo
     * @param userInfo
     * @return
     */
    @Override
    public List<QmcyCustLicaiSaleinfo> productExpireLcGgc(QmcyCustLicaiSaleinfo qmcyCustLicaiSaleinfo, LoginUser userInfo) {
        List<QmcyCustLicaiSaleinfo> doList = new ArrayList<QmcyCustLicaiSaleinfo>();

        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        if (userInfo.getRoles().contains("admin") || userInfo.getRoles().contains("office")) {
        	qmcyCustLicaiSaleinfo.setUserId(userId);
        } else if(userInfo.getRoles().contains("zhhz")){
        	qmcyCustLicaiSaleinfo.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
        	qmcyCustLicaiSaleinfo.setOrgId(orgId);
        } else {
        	return doList;
        }


        doList = qmcyCustLicaiSaleinfoMapper.productExpireLcGgc(qmcyCustLicaiSaleinfo);

        return doList;
    }

    /**
     * 存款产品到期提醒
     * @param qmcyCustCksd
     * @param userInfo
     * @return
     */
    @Override
    public List<QmcyCustCksd> productExpireCkMore(QmcyCustCksd qmcyCustCksd, LoginUser userInfo) {
        List<QmcyCustCksd> doList = new ArrayList<QmcyCustCksd>();

        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        if(userInfo.getRoles().contains("zhhz")){
            qmcyCustCksd.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
            qmcyCustCksd.setOrgId(orgId);
            qmcyCustCksd.setUserId(userId);
        } else {
            qmcyCustCksd.setOrgId("");
            qmcyCustCksd.setUserId("");
        }

        doList = qmcyCustCksdMapper.productExpire(qmcyCustCksd);

        return doList;
    }

    /**
     * 存款产品到期提醒
     * @param qmcyCustCksd
     * @param userInfo
     * @return
     */
    @Override
    public List<QmcyCustCksd> productExpireCkGgc(QmcyCustCksd qmcyCustCksd, LoginUser userInfo) {
        List<QmcyCustCksd> doList = new ArrayList<QmcyCustCksd>();

        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        if (userInfo.getRoles().contains("admin") || userInfo.getRoles().contains("office")) {
        	qmcyCustCksd.setUserId(userId);
        } else if(userInfo.getRoles().contains("zhhz")){
        	qmcyCustCksd.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
        	qmcyCustCksd.setOrgId(orgId);
        } else {
        	return doList;
        }

        doList = qmcyCustCksdMapper.productExpireCkGgc(qmcyCustCksd);

        return doList;
    }

    /**
     * 客户生日提醒
     * @param userInfo
     * @return
     */
    @Override
    public List<DataCustomerInfo> queryBirthDayTadayMore(LoginUser userInfo) {
        DataCustomerInfo dataCustomerInfo = new DataCustomerInfo();
        String key = "";
        List<DataCustomerInfo> doList = new ArrayList<>();

        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        // 提前四天的日期
        String now = new SimpleDateFormat("MMdd").format(DateUtilss.getdate(4));
        dataCustomerInfo.setBirthday(now);

        if(userInfo.getRoles().contains("zhhz")){
            dataCustomerInfo.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
            dataCustomerInfo.setOrgId(orgId);
            dataCustomerInfo.setUserId(userId);
        }

        doList = dataCustomerInfoMapper.queryBirthDayTadayZongHMore(dataCustomerInfo);

        return doList;
    }

    /**
     * 客户生日提醒
     * @param userInfo
     * @return
     */
    @Override
    public List<DataCustomerInfo> queryBirthDayTadayGgc(LoginUser userInfo) {
        DataCustomerInfo dataCustomerInfo = new DataCustomerInfo();
        String key = "";
        List<DataCustomerInfo> doList = new ArrayList<>();

        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        // 提前四天的日期
        String now = new SimpleDateFormat("MMdd").format(DateUtilss.getdate(4));
        dataCustomerInfo.setCustomerLevelZh(now);

        if (userInfo.getRoles().contains("admin") || userInfo.getRoles().contains("office")) {
        	dataCustomerInfo.setUserId(userId);
        } else if(userInfo.getRoles().contains("zhhz")){
        	dataCustomerInfo.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
        	dataCustomerInfo.setOrgId(orgId);
        } else {
        	return doList;
        }

        doList = dataCustomerInfoMapper.queryBirthDayTadayGgc(dataCustomerInfo);

        return doList;
    }

    /**
     * 客户贡献度升降
     * @param userInfo
     * @return
     */
    @Override
    public List<QmcyCustPersonalInfo> productExpireKhGxMore(LoginUser userInfo) {
        QmcyCustPersonalInfo qmcyCqustPersonalInfo = new QmcyCustPersonalInfo();
        String key = "";
        List<QmcyCustPersonalInfo> doList = new ArrayList<>();

        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        if(userInfo.getRoles().contains("zhhz")){
            qmcyCqustPersonalInfo.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
            qmcyCqustPersonalInfo.setOrgId(orgId);
            qmcyCqustPersonalInfo.setUserId(userId);
        }

        doList = qmcyCustPersonalInfoMapper.productExpireKhGx(qmcyCqustPersonalInfo);

        return doList;
    }

    /**
     * 存款TOP10
     * @param userInfo
     * @return
     */
    @Override
    public List<DataCustomerBankRelation> ckTop(DataCustomerBankRelation dataCustomerBankRelation,LoginUser userInfo) {
        List<DataCustomerBankRelation> doList = new ArrayList<>();
        String orgId = "";
        String userId = "";

        if(userInfo.getRoles().contains("zhhz")){
            orgId = userInfo.getSysUser().getDept().getOrgId();
        } else if(userInfo.getRoles().contains("common")){
            orgId = userInfo.getSysUser().getDept().getOrgId();
            userId = userInfo.getSysUser().getUserName();
        }

        //0对私1对公
        String dgds = dataCustomerBankRelation.getDgds();
        if(dgds != null) {
            doList = dataCustomerBankRelationMapper.ckTopDgDs(orgId, userId, dgds);
        }else {
            doList = dataCustomerBankRelationMapper.ckTop(orgId, userId);
        }

        return doList;
    }

    /**
     * 贷款TOP10
     * @param userInfo
     * @return
     */
    @Override
    public List<DataCustomerBankRelation> dkTop(DataCustomerBankRelation dataCustomerBankRelation,LoginUser userInfo) {
        List<DataCustomerBankRelation> doList = new ArrayList<>();
        String orgId = "";
        String userId = "";

        if(userInfo.getRoles().contains("zhhz")){
            orgId = userInfo.getSysUser().getDept().getOrgId();
        } else if(userInfo.getRoles().contains("common")){
            orgId = userInfo.getSysUser().getDept().getOrgId();
            userId = userInfo.getSysUser().getUserName();
        }

        //0对私1对公
        String dgds = dataCustomerBankRelation.getDgds();

        doList = dataCustomerBankRelationMapper.dkTop(orgId, userId, dgds);

        return doList;
    }

    /**
     * 资金流出top10
     * @param qmcyCustZhjy
     * @param userInfo
     * @return
     */
    @Override
    public List<QmcyCustZhjy> zjlcTop(QmcyCustZhjy qmcyCustZhjy, LoginUser userInfo) {
        List<QmcyCustZhjy> doList = new ArrayList<>();
        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        if(userInfo.getRoles().contains("zhhz")){
            qmcyCustZhjy.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
            qmcyCustZhjy.setOrgId(orgId);
            qmcyCustZhjy.setUserId(userId);
        }

        AjaxResult paramJe = remoteConfigService.selectConfigByKey(Params.DEZJTX_JE);
//        AjaxResult paramTs = remoteConfigService.selectConfigByKey(Params.DEZJTX_SJ);
//        String date = DateUtils.getBefoDate(Integer.valueOf(paramTs.get("data").toString()));
        qmcyCustZhjy.setJffse(new BigDecimal(paramJe.get("msg").toString()));

        //0对私1对公
        if("0".equals(qmcyCustZhjy.getDgds())) {
            doList = qmcyCustZhjyMapper.zjlcTopDs(qmcyCustZhjy);
        }else if("1".equals(qmcyCustZhjy.getDgds())){
            doList = qmcyCustZhjyMapper.zjlcTopDg(qmcyCustZhjy);
        }else {
            doList = qmcyCustZhjyMapper.zjlcTop(qmcyCustZhjy);
        }

        return doList;
    }

    @Override
    public List<Map<String, Object>> bt() {
        return dataCustomerInfoMapper.bt();
    }

    @Override
    public List<QmcyCustPersonalInfo> zhqst(QmcyCustPersonalInfo qmcyCustPersonalInfo, LoginUser userInfo) {
        List<QmcyCustPersonalInfo> doList = new ArrayList<QmcyCustPersonalInfo>();
        List<QmcyCustPersonalInfo> doLists = new ArrayList<QmcyCustPersonalInfo>();

        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        if(userInfo.getRoles().contains("zhhz")){
            qmcyCustPersonalInfo.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
            qmcyCustPersonalInfo.setOrgId(orgId);
            qmcyCustPersonalInfo.setUserId(userId);
        }

        //上个月数据
        QmcyCustPersonalInfo lastMonth = new QmcyCustPersonalInfo();

        /**
         * 获取一年内每个月最后一天
         */
        ArrayList<String> sjrqs = DateUtilss.getEndMonthByYear(1, 0);
        sjrqs.add(DateUtilss.getLastYear(new Date(), -1));
        qmcyCustPersonalInfo.setSjrqs(sjrqs);
        doList = qmcyCustPersonalInfoMapper.zhqst(qmcyCustPersonalInfo);
        for(QmcyCustPersonalInfo tmp:doList) {
            if(!StringUtils.isEmpty(tmp.getSjrq())) {
                if(DateUtilss.getLastYear(new Date(), -1).equals(tmp.getSjrq())) {
                    lastMonth = tmp;
                }
            }
        }

        if(lastMonth.getSjrq()==null) {
            lastMonth.setSjrq(DateUtilss.getLastYear(new Date(), -1));
        }

        for(int i = 0;i<doList.size();i++) {
            //本月的数据 减去上个月的数据 得出本月净增
            QmcyCustPersonalInfo zhqsts = new QmcyCustPersonalInfo();
            if(!DateUtilss.getLastYear(new Date(), -1).equals(doList.get(i).getSjrq())) {
                doList.get(i).setCkze(doList.get(i).getCkze() == null ? new BigDecimal(0):doList.get(i).getCkze());
                doList.get(i).setDkye(doList.get(i).getDkye() == null ? new BigDecimal(0):doList.get(i).getDkye());


                zhqsts.setCkze(doList.get(i).getCkze().subtract(lastMonth.getCkze() == null ? new BigDecimal(0):lastMonth.getCkze()));
                zhqsts.setDkye(doList.get(i).getDkye().subtract(lastMonth.getDkye() == null ? new BigDecimal(0):lastMonth.getDkye()));
                zhqsts.setSfsbk(String.valueOf(Integer.parseInt(doList.get(i).getSfsbk()) - Integer.parseInt(lastMonth.getSfsbk() == null ? "0":lastMonth.getSfsbk())));
                zhqsts.setSfsjyh(String.valueOf(Integer.parseInt(doList.get(i).getSfsjyh()) - Integer.parseInt(lastMonth.getSfsjyh() == null ? "0":lastMonth.getSfsjyh())));
                zhqsts.setSfsyb(String.valueOf(Integer.parseInt(doList.get(i).getSfsyb()) - Integer.parseInt(lastMonth.getSfsyb() == null ? "0":lastMonth.getSfsyb())));
                zhqsts.setSfxyk(String.valueOf(Integer.parseInt(doList.get(i).getSfxyk()) - Integer.parseInt(lastMonth.getSfxyk() == null ? "0":lastMonth.getSfxyk())));
                zhqsts.setSjrq(doList.get(i).getSjrq());
                //本次循环结束将本月的数据赋值到上个月
                doLists.add(zhqsts);
                lastMonth = doList.get(i);
            }

        }
        return doList;
    }

    @Override
    public List<DataWgShsurvey> getWgshSurveyList(DataWgShsurvey dataWgShsurvey, LoginUser userInfo) {

        /**
         * 判断数据日期是否为近3年4个季度以及当年每个月月末
         */
        ArrayList<String> sjrqs = DateUtilss.getThreeYearFourQuarterAndMonth();
        dataWgShsurvey.setSjrqs(sjrqs);

        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        if(userInfo.getRoles().contains("zhhz")){
            dataWgShsurvey.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
            dataWgShsurvey.setOrgId(orgId);
            dataWgShsurvey.setUserId(userId);
        }

        List<DataWgShsurvey> doList = dataGtgshMapper.getWgshSurveyList(dataWgShsurvey);
        return doList;
    }

    @Override
    public List<DataWgWgcjVillage> getWgcjSurveyList(DataWgWgcjVillage dataWgWgcjVillage, LoginUser userInfo) {
        /**
         * 判断数据日期是否为近3年4个季度以及当年每个月月末
         */
        ArrayList<String> sjrqs = DateUtilss.getThreeYearFourQuarterAndMonth();
        dataWgWgcjVillage.setSjrqs(sjrqs);

        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        if(userInfo.getRoles().contains("zhhz")){
            dataWgWgcjVillage.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
            dataWgWgcjVillage.setOrgId(orgId);
            dataWgWgcjVillage.setUserId(userId);
        }

        List<DataWgWgcjVillage> doList = dataWgWgcjVillageMapper.getWgcjSurveyList(dataWgWgcjVillage);
        return doList;
    }

    @Override
    public List<DataWgWgsqSq> getWgsqSurveyList(DataWgWgsqSq dataWgWgsqSq, LoginUser userInfo) {
        /**
         * 判断数据日期是否为近3年4个季度以及当年每个月月末
         */
        ArrayList<String> sjrqs = DateUtilss.getThreeYearFourQuarterAndMonth();
        dataWgWgsqSq.setSjrqs(sjrqs);

        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        if(userInfo.getRoles().contains("zhhz")){
            dataWgWgsqSq.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
            dataWgWgsqSq.setOrgId(orgId);
            dataWgWgsqSq.setUserId(userId);
        }

        List<DataWgWgsqSq> doList = dataWgWgsqSqMapper.getWgsqSurveyList(dataWgWgsqSq);
        return doList;
    }

    @Override
    public Map<String,String> xjkhProportionDgds(String sfdg, LoginUser userInfo) {
        Map<String,String> map = new HashMap<String, String>();

        String orgId = "";
        String userId = "";

        if(userInfo.getRoles().contains("zhhz")){
            orgId = userInfo.getSysUser().getDept().getOrgId();
            map.put("orgId", orgId);
        } else if(userInfo.getRoles().contains("common")){
            orgId = userInfo.getSysUser().getDept().getOrgId();
            userId = userInfo.getSysUser().getUserName();
            map.put("orgId", orgId);
            map.put("userId", userId);
        }

        map.put("sfdg",sfdg);
        return qmcyCustPersonalInfoMapper.xjkhProportion(map);
    }
    
    public List<AdvanceHk> getAdvanceHkMore( LoginUser userInfo) {
    	 String orgId = userInfo.getSysUser().getDept().getOrgId();
         String userId = userInfo.getSysUser().getUserName();;
		List<AdvanceHk> doList = new ArrayList<AdvanceHk>();
		AdvanceHk advanceHk = new AdvanceHk();

		if (userInfo.getRoles().contains("admin") || userInfo.getRoles().contains("office")) {
			//总行
			advanceHk.setOrgId(null);
			advanceHk.setUserId(null);
		} else if(userInfo.getRoles().contains("zhhz")){
			//支行
			advanceHk.setOrgId(orgId);
			advanceHk.setUserId(null);
		 } else if(userInfo.getRoles().contains("common")){
			//客户经理
			advanceHk.setOrgId(orgId);
			advanceHk.setUserId(userId);
		} else {
			return doList;
        }
//		PageHelper.orderBy("CRJE DESC");
		doList = qmcyCustPersonalInfoMapper.getAdvanceHkMore(advanceHk); // 总行查询
		
		return doList;
	}
}
